package com.ljw.community.service.impl;

import com.ljw.community.entity.Admin;
import com.ljw.community.entity.User;
import com.ljw.community.mapper.AdminMapper;
import com.ljw.community.mapper.UserMapper;
import com.ljw.community.service.CommonService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class CommonServiceImpl implements CommonService {

    @Resource
    private UserMapper userMapper;
    @Resource
    private AdminMapper adminMapper;


    @Override
    public String login(String loginName, String password, String type) {
        if (type.equals("user")) {
            User dbUser = userMapper.getByLoginName(loginName);
            if (dbUser == null || !password.equals(dbUser.getPassword())) {
                return "登录名或密码错误";  //登录名或密码错误
            } else if (dbUser.getState().equals("0")) {
                return "该用户还在审核中"; //审核中
            } else if (dbUser.getState().equals("-1")) {
                return "该用户未通过审核,请重新提交注册申请"; //未通过审核
            } else if (dbUser.getState().equals("2")) {
                return "该用户封禁中"; //封禁中
            } else {
                return ""; //成功
            }
        } else if (type.equals("admin")) {
            Admin dbAdmin = adminMapper.getByLoginName(loginName);
            if (dbAdmin == null || !password.equals(dbAdmin.getPassword())) {
                return "登录名或密码错误";  //登录名或密码错误
            } else {
                return ""; //成功
            }
        }
        return "error";  //系统错误
    }
}
